<?php

namespace extend;

class Verify
{

    static function regex($regex,$val){
        return preg_match("/$regex/",$val);
    }

    static function number($val): bool
    {
        return preg_match("/^[0-9]*$/",$val);
    }

    static function chs($val): bool
    {
        return preg_match("/^[\u4e00-\u9fa5]{*}$/",$val);
    }


    static function email($val): bool
    {
        return preg_match("/^\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$/",$val);
    }


    static function mobile($val): bool
    {
        return preg_match("/^1[3456789]\d{9}$/",$val);
    }


    static function url($val): bool
    {
        return preg_match("/^[a-zA-z]+://(\w+(-\w+))(\.(\w+(-\w+)))(\?\S)?$/i",$val);
    }

    static function ip($val): bool
    {
        return preg_match("/^((?:(?:25[0-5]|2[0-4]\d|((1\d{2})|([1-9]?\d)))\.){3}(?:25[0-5]|2[0-4]\d|((1\d{2})|([1 -9]?\d))))$/",$val);
    }

    static function area_level($val,$params){

        if(!$params) return true;

        $row=db()->where('code',$val)->getOne(AREA_DATA_TABLE);

        return $row && $row['level']==(int)$params;
    }
}